package controllers

import (
	"github.com/gin-gonic/gin"
	"wakitsoft.com/resume/config"
	"wakitsoft.com/resume/errs"
	"wakitsoft.com/resume/libs"
)

type Image struct {
	Image string `json:"image"`
}

func UploadImage(c *gin.Context) {
	webUrl := config.Instance().App.Web.Url
	var req Image
	if !libs.ValidateRequest(c, &req) {
		return
	}
	if url, err := libs.SaveBase64ImageToFile(req.Image, "uploads/images"); err != nil {
		libs.Error(c, errs.BadRequest, err.Error())
	} else {
		libs.Success(c, webUrl+"/"+url)
	}
}
